package com.lyl.myaiagent.servertools.tools;

import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;

/**
 * @author lyl
 * @version 1.0
 * @CreateTime: 2025-08-19
 */
@Slf4j
public class WebScrapingTool {
    @Tool(description = "scrape the content of web page")
    public String scrapeWeb(@ToolParam(description = "url of the web to scrape") String url){
        log.info("开始抓取网页");
        try {
            Document document = Jsoup.connect(url).get();
            log.info("网页抓取完毕");
            return document.toString();
        } catch (Exception e) {
            log.error("网页抓取有误");
            return "Error scraping the web page: " + e.getMessage();
        }
    }
}
